#pragma once

#include "includes.h"

float sizeOfTile = 4.0;

void table_leg()
{
	GLUquadric* cylinder;
	GLUquadric* cylinder2;
	cylinder = gluNewQuadric();
	cylinder2 = gluNewQuadric();

	glPushMatrix();
		glTranslated(0,-1,0);
		glRotatef(90.0,1.0,0.0,0.0);
		gluCylinder(cylinder, 2, 0.2, 11, 20, 20);
	glPopMatrix();
	glPushMatrix();
		glTranslated(0,-12,0);
		glRotatef(90.0,1.0,0.0,0.0);
		gluCylinder(cylinder, 0.2, 2, 3, 20, 20);
	glPopMatrix();
}

void draw_landscape(int size, int size_of_tile, unsigned int floor, unsigned int wall)
{
	glEnable(GL_TEXTURE_2D);
		
	glPushMatrix();
		glTranslated(-35,-15,-35);
		glBindTexture(GL_TEXTURE_2D, floor);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(25.0,0);		glVertex3d(120,0,120);
			glTexCoord2f(25.0,25.0);	glVertex3d(120,0,0);
			glTexCoord2f(0,25.0);		glVertex3d(0,0,0);
			glTexCoord2f(0,0);			glVertex3d(0,0,120);
		glEnd();
	glPopMatrix();


	glPushMatrix();
		glTranslated(-35,-15,-35);
		glRotated(-90,1,0,0);
		glBindTexture(GL_TEXTURE_2D, wall);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0.0, 1.0);	glVertex3d(120,0,120);
			glTexCoord2f(0.0, 0.0);	glVertex3d(120,0,0);
			glTexCoord2f(1.0, 0.0);	glVertex3d(0,0,0);
			glTexCoord2f(1.0, 1.0);	glVertex3d(0,0,120);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(-35,-15,-35);
		glRotated(90,0,0,1);
		glBindTexture(GL_TEXTURE_2D, wall);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(1.0, 1.0);	glVertex3d(120,0,120);
			glTexCoord2f(0.0, 1.0);	glVertex3d(120,0,0);
			glTexCoord2f(0.0, 0.0);	glVertex3d(0,0,0);
			glTexCoord2f(1.0, 0.0);	glVertex3d(0,0,120);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(-12.5, -1, -3.5);
		glBindTexture(GL_TEXTURE_2D, 2013);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0,0.5);	glVertex3d(size*size_of_tile+30, 0.0, size*size_of_tile+10);
			glTexCoord2f(0.5,0);	glVertex3d(size*size_of_tile+30, 0.0, 0.0);
			glTexCoord2f(0.5,0.5);	glVertex3d(0.0, 0.0, 0.0);
			glTexCoord2f(0,0);		glVertex3d(0.0, 0.0, size*size_of_tile+10.0);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(-size-1, 0, -0.5);
		table_leg(); 
	glPopMatrix();

	glPushMatrix();
		glTranslated(size*size_of_tile+10, 0, -0.5);
		table_leg();
	glPopMatrix();
		  
	glPushMatrix();
		glTranslated(-size-1, 0,  size*size_of_tile+2);
		table_leg();
	glPopMatrix();

	glPushMatrix();
		glTranslated(size*size_of_tile+10, 0, size*size_of_tile+2);
		table_leg();
	glPopMatrix();


	glPushMatrix();
		glTranslated(size_of_tile*0.5,0,size_of_tile*0.5);
		glRotated(90,1,0,0);
		glBindTexture(GL_TEXTURE_2D, 2014);
		glBegin(GL_POLYGON);
		glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0,0.5);	 glVertex3d(size*size_of_tile,0,1);
			glTexCoord2f(0.5,0);	 glVertex3d(size*size_of_tile,0,0);
			glTexCoord2f(0.5,0.5);	 glVertex3d(0,0,0);
			glTexCoord2f(0,0);		 glVertex3d(0,0,1);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(size_of_tile*0.5,0,size*size_of_tile+size_of_tile*0.5);
		glRotated(90,1,0,0);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0,0.5);	 glVertex3d(size*size_of_tile,0,1);
			glTexCoord2f(0.5,0);	 glVertex3d(size*size_of_tile,0,0);
			glTexCoord2f(0.5,0.5); 	 glVertex3d(0,0,0);
			glTexCoord2f(0,0);		 glVertex3d(0,0,1);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(size_of_tile*0.5,0,size_of_tile*0.5);
		glRotated(-90,0,0,1);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0,0.5);	glVertex3d(1,0,size*size_of_tile);
			glTexCoord2f(0.5,0);	glVertex3d(1,0,0);
			glTexCoord2f(0.5,0.5);	glVertex3d(0,0,0);
			glTexCoord2f(0,0);		glVertex3d(0,0,size*size_of_tile);
		glEnd();
	glPopMatrix();


	glPushMatrix();
		glTranslated(size*size_of_tile+size_of_tile*0.5,0,size_of_tile*0.5);
		glRotated(-90,0,0,1);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glTexCoord2f(0,0.5); glVertex3d(1,0,size*size_of_tile);
			glTexCoord2f(0.5,0); glVertex3d(1,0,0);
			glTexCoord2f(0.5,0.5); glVertex3d(0,0,0);
			glTexCoord2f(0,0); glVertex3d(0,0,size*size_of_tile);
		glEnd();
	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}


void draw_box(char currentPlayer, int size, int size_of_tile)
{
	float pieceRadius = 3.0*size_of_tile/8.0;
	float boxL = 3.0*size_of_tile/2.0+pieceRadius/2.0;
	float boxC = 9.0*size_of_tile/4.0;
	float boxH = boxL/4.0;
	float transX = 0.0;
	float transZ = size*size_of_tile/2.0 + size_of_tile/2.0;
		
	glPushMatrix();
		glTranslated(transX, 0.0, transZ);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glVertex3d(boxC/2.0, 0.0, boxL/2.0);
			glVertex3d(boxC/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxC/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxC/2.0, 0, boxL/2.0);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX, 0.0, transZ-(boxL/2.0));
		glRotated(-90.0, 1.0, 0.0, 0.0);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glVertex3d(-boxC/2.0, 0.0, boxH/2.0);
			glVertex3d(-boxC/2.0, 0.0, -boxH/2.0);
			glVertex3d(boxC/2.0, 0.0, -boxH/2.0);
			glVertex3d(boxC/2.0, 0.0, boxH/2.0);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX, 0.0, transZ+(boxL/2.0));
		glRotated(-90.0, 1.0, 0.0, 0.0);
		glBegin(GL_POLYGON);
		glNormal3d(0.0, 1.0, 0);
			glVertex3d(-boxC/2.0, 0.0, boxH/2.0);
			glVertex3d(-boxC/2.0, 0.0, -boxH/2.0);
			glVertex3d(boxC/2.0, 0.0, -boxH/2.0);
			glVertex3d(boxC/2.0, 0.0, boxH/2.0);
		glEnd();
	glPopMatrix();


	glPushMatrix();
		glTranslated(transX-(boxC/2.0), 0.0, transZ);
		glRotated(90.0, 0.0, 0.0, 1.0);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glVertex3d(boxH/2.0, 0.0, boxL/2.0);
			glVertex3d(boxH/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxH/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxH/2.0, 0.0, boxL/2.0);
		glEnd();
	glPopMatrix();


	glPushMatrix();
		glTranslated(transX+(boxC/2.0), 0.0, transZ);
		glRotated(90.0, 0.0, 0.0, 1.0);
		glBegin(GL_POLYGON);
			glNormal3d(0.0, 1.0, 0);
			glVertex3d(boxH/2.0, 0.0, boxL/2.0);
			glVertex3d(boxH/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxH/2.0, 0.0, -boxL/2.0);
			glVertex3d(-boxH/2.0, 0.0, boxL/2.0);
		glEnd();
	glPopMatrix();


	Piece * Generic_piece = new Piece(0, 0, 0, currentPlayer, sizeOfTile);

	glPushMatrix();
		glTranslated(transX-pieceRadius*2.0, pieceRadius/4.0, transZ-pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX-pieceRadius*2.0, pieceRadius/4.0, transZ+pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX+pieceRadius*2.0, pieceRadius/4.0, transZ-pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX+pieceRadius*2.0, pieceRadius/4.0, transZ+pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX, pieceRadius/4.0, transZ-pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX, pieceRadius/4.0, transZ+pieceRadius);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX+pieceRadius, pieceRadius/2.0, transZ);
		Generic_piece->render();
	glPopMatrix();

	glPushMatrix();
		glTranslated(transX-pieceRadius, pieceRadius/2.0, transZ);
		Generic_piece->render();
	glPopMatrix();
}

void drawStopwatch()
{
	float stopwatchHeight = 2.0;
	float stopwatchWidth = 2.0;
	float stopwatchLength = 3.0;

	glBegin(GL_POLYGON);
		glNormal3d(1.0, 0.0, 0.0);
		glVertex3d(stopwatchWidth/2.0, 0.0, -stopwatchLength/2.0);
		glVertex3d(stopwatchWidth/2.0, stopwatchHeight, -stopwatchLength/2.0);
		glVertex3d(-stopwatchWidth/2.0, stopwatchHeight, -stopwatchLength/2.0);
		glVertex3d(-stopwatchWidth/2.0, 0.0, -stopwatchLength/2.0);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3d(0.0, 1.0, 0.0);
		glVertex3d(stopwatchWidth/2.0, 0.0, 0.0);
		glVertex3d(stopwatchWidth/2.0, stopwatchHeight, 0.0);
		glVertex3d(-stopwatchWidth/2.0, stopwatchHeight, 0.0);
		glVertex3d(-stopwatchWidth/2.0, 0.0, 0.0);
	glEnd();
}